//
//  YXMaskAlertViewVC.m
//  YXKitOC
//
//  Created by zhxin on 2020/8/20.
//  Copyright © 2020 张鑫. All rights reserved.
//

#import "YXMaskAlertViewVC.h"
#import "YXKitOC.h"

@interface YXMaskAlertViewVC ()

@end

@implementation YXMaskAlertViewVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *titles = @[@"alert样式", @"actionsheet样式"];
    for (int i = 0; i < titles.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(i * 150, YX_SafeArea_Top() + 10, 150, 44);
        [btn setTitle:titles[i] forState:0];
        [btn setTitleColor:YX_BlackColor() forState:0];
        btn.yx_borderColor = YX_BlueColor();
        btn.yx_borderWidth = 0.5;
        btn.yx_cornerRadius = 5;
        [self.view addSubview:btn];
        
        [btn yx_addEventBlock:^(id  _Nonnull sender) {
            
            UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 80)];
            [closeBtn setTitle:@"关闭" forState:0];
            [closeBtn setTitleColor:YX_BlackColor() forState:0];
            UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, i == 0 ? self.view.width * 0.7 : self.view.width, 250)];
            customView.backgroundColor = YX_RandomColor();
            [customView addSubview:closeBtn];
            [closeBtn yx_alignmentCenter];
            
            YXMaskAlertView *maskView = [YXMaskAlertView showWithContentView:customView showType:i == 0 ? YXMaskAlertViewShowType_Alert : YXMaskAlertViewShowType_ActionSheet];
            
            [closeBtn yx_addEventBlock:^(id  _Nonnull sender) {
                [maskView close];
            }];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                customView.height += 50;
                [maskView reloadContentViewSize];
            });
        }];
    }
    
    /** 占位图，只有符合尺寸的才显示占位图，（不支持约束布局） */
    // 配置默认占位图
    YXImageViewConfig.sharedYXImageViewConfig.defaultPlaceholderImage = YX_ImageNamed(@"yx_image_nodata");
    YXImageViewConfig.sharedYXImageViewConfig.defaultPlaceholderMaxSize = CGSizeMake(300, 200);
    YXImageViewConfig.sharedYXImageViewConfig.defaultPlaceholderMinSize = CGSizeMake(100, 80);
    
    UIImageView *imageView0 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 150, 150, 150)];
    imageView0.backgroundColor = YX_GroupTableViewBackgroundColor();
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(180, 150, 150, 150)];
    imageView1.backgroundColor = YX_GroupTableViewBackgroundColor();
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 300, 60, 60)];
    imageView2.backgroundColor = YX_GroupTableViewBackgroundColor();
    UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 380, 300, 300)];
    imageView3.backgroundColor = YX_GroupTableViewBackgroundColor();
    
    [imageView0 yx_setImageWithURLString:@""];
    // 满足尺寸时，强制取消占位图
    [imageView1 yx_setImageWithURLString:@"" placeholderImage:[UIImage new]];
    [imageView2 yx_setImageWithURLString:@""];
    [imageView3 yx_setImageWithURLString:@""];
    
    [self.view addSubview:imageView0];
    [self.view addSubview:imageView1];
    [self.view addSubview:imageView2];
    [self.view addSubview:imageView3];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
